package org.gitman.agentplatform.agent.impl;

import java.util.HashMap;
import java.util.Map;

import org.gitman.agentplatform.agent.api.Agent;
import org.gitman.agentplatform.agent.api.AgentFactory;
import org.gitman.agentplatform.agent.impl.cooperative.ConformableAgent;
import org.gitman.agentplatform.agent.impl.isolated.IsolatedAgent;
import org.gitman.agentplatform.agent.impl.isolated.IsolatedNotWaitingAgent;
import org.gitman.agentplatform.agent.impl.malicious.MaliciousAgent;
import org.gitman.agentplatform.agent.impl.random.RandomAgent;
import org.gitman.agentplatform.core.exceptions.BadArgsException;

public class AgentFactoryImpl implements AgentFactory{
	private Map<Class<? extends Agent>, String> agents;
	
	public AgentFactoryImpl(){
		agents = new HashMap<Class<? extends Agent>, String>();
		agents.put(RandomAgent.class, "This is a random agents. It randomly selects one of not occupied neighbours and tries to move there. This agent is used only for increasing simulation randomness");
		agents.put(IsolatedAgent.class, "This is a isolated agent that means it does not consider others plans and does not publicate its own. It can only move towards its destination, if the path is blocked it will wait for the path to be available (may cause deadlock) ");
		agents.put(IsolatedNotWaitingAgent.class, "This is a isolated agent that means it does not consider others plans and does not publicate its own. It tries to move towards destination but if the path is blocked it will not wait, but it will go another way");
		agents.put(ConformableAgent.class, "This is cooperative agent. It is conformable that mean it will adjust to all existing plan. It will always give way to agent that already have plan. It could wait or move back if this is necessary");
		agents.put(MaliciousAgent.class, "This agent acts in the same way as IsolatedNotWaitingAgent, but deliberately publicate wrong plan to missinform other agents");
	}
	@Override
	public Agent getAgentImpl(Class<? extends Agent> clazz, String args)
			throws BadArgsException {
		Agent agent = null;
		try {
			agent = clazz.newInstance();
			agent.init(args);
		} catch (Exception e) {
			throw new BadArgsException("can't create new agent: " + clazz.getName());
		}
		return agent;
	}
	@Override
	public Map<Class<? extends Agent>, String> getAvailableAgents() {
		return agents;
	}

}
